//
//  CHNBaseViewController.m
//  TestDemo
//
//  Created by 张润东 on 2021/8/19.
//

#import "CHNBaseViewController.h"
#import <RTRootNavigationController/UIViewController+RTRootNavigationController.h>

@interface CHNBaseViewController ()

@end

@implementation CHNBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self defaultNavStyle];
}

-(void)defaultNavStyle{
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;//状态栏的黑色/白色字体
    [self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[UIColor orangeColor]] forBarMetrics:UIBarMetricsDefault];//颜色
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    [self.navigationController.navigationBar setTranslucent:NO];
    self.navigationController.automaticallyAdjustsScrollViewInsets = NO;
}

- (UIImage*)imageWithColor:(UIColor *)color{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData* imageData = UIImageJPEGRepresentation(image, 1.0f);
    image = [UIImage imageWithData:imageData];
    return image;
}

-(UIBarButtonItem*)rt_customBackItemWithTarget:(id)target action:(SEL)action{
    
    UIButton *backBtn = [[UIButton alloc]init];
    backBtn.backgroundColor=[UIColor blackColor];
    backBtn.frame=CGRectMake(0, 0, 60, 38);
    [backBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc]initWithCustomView:backBtn];;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
